/**
 * 页面加载
 */
charset = "utf-8";
$(function() {
			render();
			var content = "您好，我是专业的小蜜君，提供优质的服务和准确的答案是我使命～小蜜将竭诚为您效劳 (*^__^*)";
			content += "<br/>回复[帮助]可以查看所有可用的指令。";
			// 添加公众号的开场白
			appendDialog("talk_recordbox", "小蜜", content);
			render();
		});

/**
 * 发送消息
 * 
 * @param basePath
 */
function send() {
	var content = $("#content").val();
	if (!content) {
		alert("请输入内容！");
		return;
	}
	$.ajax({
				url : "/autoreplay",
				type : "POST",
				dataType : "text",
				timeout : 10000,
				success : function(data) {
					appendDialog("talk_recordboxme", "我", content);
					appendDialog("talk_recordbox", "小蜜", data);
					$("#content").val("");
					render();
				},
				ContentType : "application/text;charset=utf-8",
				data : {
					"content" : content
				}
			});
}

/**
 * 渲染方法，加载滚动条
 */

/**
 * 向聊天记录中添加聊天内容
 * 
 * @param myClass
 *            添内容的样式
 * @param name
 *            发送消息的账号名称
 * @param content
 *            发送的内容
 */
function appendDialog(myClass, name, content) {
	var div = "";
	div += "<div class='" + myClass + "'>";
	div += "<div class='user'><img src='" + $("#basePath").val()
			+ "/resources/images/thumbs/" + myClass + ".jpg'/>" + name
			+ "</div>";
	div += "<div class='talk_recordtextbg'>&nbsp;</div>";
	div += "<div class='talk_recordtext'>";
	div += "<h3>" + content + "</h3>";
	div += "<span class='talk_time'>" + getCurrentDate() + "</span>";
	div += "</div>";
	div += "</div>";
	$('#jp-container').children().eq(0).children().eq(0).append(div);

}

/**
 * 获取当前系统时间
 * 
 * @returns {String} 当前系统时间
 */
function getCurrentDate() {
	var date = new Date();
	return date.getFullYear()
			+ "-"
			+ (date.getMonth() + 1)
			+ "-"
			+ date.getDate()
			+ " "
			+ (date.getHours() < 10 ? "0" + date.getHours() : date.getHours())
			+ ":"
			+ (date.getMinutes() < 10 ? "0" + date.getMinutes() : date
					.getMinutes());
}